//
//  SortDetailedCollectionViewCell.m
//  MountEverestFM
//
//  Created by dllo on 15/10/30.
//  Copyright © 2015年 chenn. All rights reserved.
//

#import "SortDetailedCollectionViewCell.h"
#import "SortDetailedTableViewCell.h"
#import "SortDetailedTVC.h"
#import "SortDetailedGDTableViewCell.h"
#import "SortMoreViewController.h"
#import "SortLaoShuShiCell.h"
#import "BestMusicListTableViewCell.h"
@implementation SortDetailedCollectionViewCell
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.tableView=[[UITableView alloc]init];
        self.tableView.delegate=self;
        self.tableView.dataSource=self;
        [self.contentView addSubview:self.tableView];
        
    
        
        
    }
    return self;
}
- (NSInteger) numberOfSectionsInTableView:(UITableView *)tableView
{
    return self.arr.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
      return [[[self.arr objectAtIndex:section] objectForKey:@"list"] count];

}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if ([[self.arr objectAtIndex:0] objectForKey:@"contentType"]==nil) {
        if (indexPath.section == 0&&indexPath.row==0) {
            SortDetailedTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"asd"];
            if (!cell) {
                cell=[[SortDetailedTableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"asd"];
                
            }
            
            
            cell.lable1.text=[[[[self.arr objectAtIndex:indexPath.row] objectForKey:@"list"] objectAtIndex:indexPath.row] objectForKey:@"title"];
            cell.lable2.text=[[[[self.arr objectAtIndex:indexPath.row] objectForKey:@"list"] objectAtIndex:indexPath.row] objectForKey:@"subtitle"];
            cell.imageV3.image=[UIImage imageNamed:@"cell_arrow_all.png"];
            
            NSString *str=[[[[self.arr objectAtIndex:indexPath.row] objectForKey:@"list"] objectAtIndex:indexPath.row] objectForKey:@"coverPath"];
            
            [cell.imageV sd_setImageWithURL:[NSURL URLWithString:str] placeholderImage:[UIImage imageNamed:@"find_kind_btn_default@3x.png"]];
            
            return cell;
            
        }else if (indexPath.section == 2){
            if ([[self.arr objectAtIndex:2] objectForKey:@"tagName"]==nil) {
                if (indexPath.row==0) {
                    
                    
                    SortDetailedGDTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"gengduo1"];
                    if (!cell) {
                        cell=[[SortDetailedGDTableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"gengduo1"];
                    }

                    cell.lableBT.text=[[self.arr objectAtIndex:2] objectForKey:@"title"];
                    cell.imageGD.image=[UIImage imageNamed:@"findsection_logo@2x.png"];
                    cell.lableGD.text=@"更多 >";
                    [cell.imageV1 sd_setImageWithURL:[[[[self.arr objectAtIndex:2] objectForKey:@"list"] objectAtIndex:0] objectForKey:@"coverPathSmall"] placeholderImage:[UIImage imageNamed:@"find_kind_btn_default@3x.png"]];
                    cell.lable1.text=[[[[self.arr objectAtIndex:2] objectForKey:@"list"] objectAtIndex:0] objectForKey:@"title"];
                    cell.lable2.text=[[[[self.arr objectAtIndex:2] objectForKey:@"list"] objectAtIndex:0] objectForKey:@"subtitle"];
                   
                    
                    
                    
                    cell.lable3.text=[[[[self.arr objectAtIndex:2] objectForKey:@"list"] objectAtIndex:0] objectForKey:@"footnote"];
                    
                    cell.imageV2.image=[UIImage imageNamed:@"find_hotuser_pause.png"];
                     cell.imV.image=[UIImage imageNamed:@"cell_arrow_all.png"];
                    [cell.button addTarget:self action:@selector(buttonqwe:) forControlEvents:UIControlEventTouchUpInside];
                    return cell;

                }else{
                    
                    SortDetailedTVC *cell=[tableView dequeueReusableCellWithIdentifier:@"aaaaa"];
                    if (!cell) {
                        cell=[[SortDetailedTVC alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"aaaaa"];
                        
                    }

                    [cell.imageV1 sd_setImageWithURL:[[[[self.arr objectAtIndex:2] objectForKey:@"list"] objectAtIndex:indexPath.row] objectForKey:@"coverPathSmall"] placeholderImage:[UIImage imageNamed:@"find_kind_btn_default@3x.png"]];
                    cell.lable1.text=[[[[self.arr objectAtIndex:2] objectForKey:@"list"] objectAtIndex:indexPath.row] objectForKey:@"title"];
                    cell.lable2.text=[[[[self.arr objectAtIndex:2] objectForKey:@"list"] objectAtIndex:indexPath.row] objectForKey:@"subtitle"];
                    cell.lable3.text=[[[[self.arr objectAtIndex:2] objectForKey:@"list"] objectAtIndex:indexPath.row] objectForKey:@"footnote"];
                    cell.imageV2.image=[UIImage imageNamed:@"find_hotuser_pause.png"];
                    cell.imV.image=[UIImage imageNamed:@"cell_arrow_all.png"];
                    
                    
                    
                    
                    
                
                return cell;
                }
            }else{
                if (indexPath.row == 0) {
                    SortDetailedGDTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"gengduo"];
                    if (!cell) {
                        cell=[[SortDetailedGDTableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"gengduo"];
                    }
                    cell.lable1.text=[[[[self.arr objectAtIndex:indexPath.section] objectForKey:@"list"] objectAtIndex:0] objectForKey:@"title"];
                    cell.lable2.text=[[[[self.arr objectAtIndex:indexPath.section] objectForKey:@"list"] objectAtIndex:0] objectForKey:@"intro"];
                    
                    CGFloat f=[[[[[self.arr objectAtIndex:indexPath.section] objectForKey:@"list"] objectAtIndex:indexPath.row] objectForKey:@"playsCounts"] floatValue];
                    if (f<10000) {
                        cell.lable3.text=[NSString stringWithFormat:@"%.0f",f];
                    }else{
                        cell.lable3.text=[NSString stringWithFormat:@"%.2f万",f/10000];
                    }
                    
                    
//                    cell.lable3.text=[[[[[self.arr objectAtIndex:indexPath.section] objectForKey:@"list"] objectAtIndex:0] objectForKey:@"playsCounts"] stringValue];
                    NSString *str1=[[[[[self.arr objectAtIndex:indexPath.section] objectForKey:@"list"] objectAtIndex:0] objectForKey:@"tracksCounts"] stringValue];
                    
                    
                    
                    cell.lable4.text=[str1 stringByAppendingString:@"集"];
                    [cell.imageV1 sd_setImageWithURL:[NSURL URLWithString:[[[[self.arr objectAtIndex:indexPath.section] objectForKey:@"list"] objectAtIndex:0] objectForKey:@"coverMiddle"]] placeholderImage:[UIImage imageNamed:@"find_kind_btn_default@3x.png"]];
                    cell.imageV2.image=[UIImage imageNamed:@"sound_playtimes@3x.png"];
                    cell.imageV3.image=[UIImage imageNamed:@"album_tracks@3x.png"];
                    
                    NSString *str= [[self.arr objectAtIndex:indexPath.section] objectForKey:@"title"];
                    cell.lableBT.text=str;
                    cell.imageGD.image=[UIImage imageNamed:@"findsection_logo@2x.png"];
                    cell.lableGD.text=@"更多 >";
                    cell.imV.image=[UIImage imageNamed:@"cell_arrow_all.png"];
                    [cell.button addTarget:self action:@selector(button:) forControlEvents:UIControlEventTouchUpInside];
                    cell.button.tag=indexPath.section;
                    return cell;

                }else{
                   
                    SortDetailedTVC *cell=[tableView dequeueReusableCellWithIdentifier:@"aaa"];
                    if (!cell) {
                        cell=[[SortDetailedTVC alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"aaa"];
                        
                    }
                    cell.lable1.text=[[[[self.arr objectAtIndex:indexPath.section] objectForKey:@"list"] objectAtIndex:indexPath.row] objectForKey:@"title"];
                    cell.lable2.text=[[[[self.arr objectAtIndex:indexPath.section] objectForKey:@"list"] objectAtIndex:indexPath.row] objectForKey:@"intro"];
                    
                     CGFloat f=[[[[[self.arr objectAtIndex:indexPath.section] objectForKey:@"list"] objectAtIndex:indexPath.row] objectForKey:@"playsCounts"] floatValue];
                    if (f<10000) {
                        cell.lable3.text=[NSString stringWithFormat:@"%.0f",f];
                    }else{
                        cell.lable3.text=[NSString stringWithFormat:@"%.2f万",f/10000];
                    }
                    

                    
                    
                    
//                    cell.lable3.text=[[[[[self.arr objectAtIndex:indexPath.section] objectForKey:@"list"] objectAtIndex:indexPath.row] objectForKey:@"playsCounts"] stringValue];
                    NSString  *str=[[[[[self.arr objectAtIndex:indexPath.section] objectForKey:@"list"] objectAtIndex:indexPath.row] objectForKey:@"tracksCounts"] stringValue];
                    cell.lable4.text=[str stringByAppendingString:@"集"];
                    
                    [cell.imageV1 sd_setImageWithURL:[NSURL URLWithString:[[[[self.arr objectAtIndex:indexPath.section] objectForKey:@"list"] objectAtIndex:indexPath.row] objectForKey:@"coverMiddle"]] placeholderImage:[UIImage imageNamed:@"find_kind_btn_default@3x.png"]];
                    cell.imageV2.image=[UIImage imageNamed:@"sound_playtimes@3x"];
                    cell.imageV3.image=[UIImage imageNamed:@"album_tracks@3x.png"];
                    
                    cell.imV.image=[UIImage imageNamed:@"cell_arrow_all.png"];
                    
                    
                    return cell;

                    
                }
                
                
            }
        
        
        } else if (indexPath.row==0){

            SortDetailedGDTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"gengduo"];
            if (!cell) {
                cell=[[SortDetailedGDTableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"gengduo"];
            }
            cell.lable1.text=[[[[self.arr objectAtIndex:indexPath.section] objectForKey:@"list"] objectAtIndex:0] objectForKey:@"title"];
            cell.lable2.text=[[[[self.arr objectAtIndex:indexPath.section] objectForKey:@"list"] objectAtIndex:0] objectForKey:@"intro"];
            
            CGFloat f=[[[[[self.arr objectAtIndex:indexPath.section] objectForKey:@"list"] objectAtIndex:indexPath.row] objectForKey:@"playsCounts"] floatValue];
            if (f<10000) {
                cell.lable3.text=[NSString stringWithFormat:@"%.0f",f];
            }else{
                cell.lable3.text=[NSString stringWithFormat:@"%.2f万",f/10000];
            }

            
//            cell.lable3.text=[[[[[self.arr objectAtIndex:indexPath.section] objectForKey:@"list"] objectAtIndex:0] objectForKey:@"playsCounts"] stringValue];
            NSString *str1=[[[[[self.arr objectAtIndex:indexPath.section] objectForKey:@"list"] objectAtIndex:0] objectForKey:@"tracksCounts"] stringValue];
            cell.lable4.text=[str1 stringByAppendingString:@"集"];
            [cell.imageV1 sd_setImageWithURL:[NSURL URLWithString:[[[[self.arr objectAtIndex:indexPath.section] objectForKey:@"list"] objectAtIndex:0] objectForKey:@"coverMiddle"]] placeholderImage:[UIImage imageNamed:@"find_kind_btn_default@3x.png"]];
            cell.imageV2.image=[UIImage imageNamed:@"sound_playtimes@3x.png"];
            cell.imageV3.image=[UIImage imageNamed:@"album_tracks@3x.png"];
            
            NSString *str= [[self.arr objectAtIndex:indexPath.section] objectForKey:@"title"];
            cell.lableBT.text=str;
            cell.imageGD.image=[UIImage imageNamed:@"findsection_logo@2x.png"];
            cell.lableGD.text=@"更多 >";
            cell.imV.image=[UIImage imageNamed:@"cell_arrow_all.png"];
            [cell.button addTarget:self action:@selector(button:) forControlEvents:UIControlEventTouchUpInside];
            cell.button.tag=indexPath.section;
            return cell;
   
        }
            else
        {
            SortDetailedTVC *cell=[tableView dequeueReusableCellWithIdentifier:@"aaa"];
            if (!cell) {
                cell=[[SortDetailedTVC alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"aaa"];
                
            }
            cell.lable1.text=[[[[self.arr objectAtIndex:indexPath.section] objectForKey:@"list"] objectAtIndex:indexPath.row] objectForKey:@"title"];
            cell.lable2.text=[[[[self.arr objectAtIndex:indexPath.section] objectForKey:@"list"] objectAtIndex:indexPath.row] objectForKey:@"intro"];
            
            CGFloat f=[[[[[self.arr objectAtIndex:indexPath.section] objectForKey:@"list"] objectAtIndex:indexPath.row] objectForKey:@"playsCounts"] floatValue];
            if (f<10000) {
                cell.lable3.text=[NSString stringWithFormat:@"%.0f",f];
            }else{
                cell.lable3.text=[NSString stringWithFormat:@"%.2f万",f/10000];
            }

            
//            cell.lable3.text=[[[[[self.arr objectAtIndex:indexPath.section] objectForKey:@"list"] objectAtIndex:indexPath.row] objectForKey:@"playsCounts"] stringValue];
            NSString  *str=[[[[[self.arr objectAtIndex:indexPath.section] objectForKey:@"list"] objectAtIndex:indexPath.row] objectForKey:@"tracksCounts"] stringValue];
            cell.lable4.text=[str stringByAppendingString:@"集"];
            
            [cell.imageV1 sd_setImageWithURL:[NSURL URLWithString:[[[[self.arr objectAtIndex:indexPath.section] objectForKey:@"list"] objectAtIndex:indexPath.row] objectForKey:@"coverMiddle"]] placeholderImage:[UIImage imageNamed:@"find_kind_btn_default@3x.png"]];
            cell.imageV2.image=[UIImage imageNamed:@"sound_playtimes@3x"];
            cell.imageV3.image=[UIImage imageNamed:@"album_tracks@3x.png"];
            
            cell.imV.image=[UIImage imageNamed:@"cell_arrow_all.png"];
            
            
            return cell;
       
        }
 
    }else{
        if (indexPath.row==0) {
            SortDetailedGDTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"gengduo"];
            if (!cell) {
                cell=[[SortDetailedGDTableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"gengduo"];
            }
            cell.lable1.text=[[[[self.arr objectAtIndex:indexPath.section] objectForKey:@"list"] objectAtIndex:0] objectForKey:@"title"];
            cell.lable2.text=[[[[self.arr objectAtIndex:indexPath.section] objectForKey:@"list"] objectAtIndex:0] objectForKey:@"intro"];
            CGFloat f=[[[[[self.arr objectAtIndex:indexPath.section] objectForKey:@"list"] objectAtIndex:indexPath.row] objectForKey:@"playsCounts"] floatValue];
            if (f<10000) {
                cell.lable3.text=[NSString stringWithFormat:@"%.0f",f];
            }else{
                cell.lable3.text=[NSString stringWithFormat:@"%.2f万",f/10000];
            }

            
//            cell.lable3.text=[[[[[self.arr objectAtIndex:indexPath.section] objectForKey:@"list"] objectAtIndex:0] objectForKey:@"playsCounts"] stringValue];
            NSString *str1=[[[[[self.arr objectAtIndex:indexPath.section] objectForKey:@"list"] objectAtIndex:0] objectForKey:@"tracksCounts"] stringValue];
            cell.lable4.text=[str1 stringByAppendingString:@"集"];
            [cell.imageV1 sd_setImageWithURL:[NSURL URLWithString:[[[[self.arr objectAtIndex:indexPath.section] objectForKey:@"list"] objectAtIndex:0] objectForKey:@"coverMiddle"]] placeholderImage:[UIImage imageNamed:@"find_kind_btn_default@3x.png"]];
            cell.imageV2.image=[UIImage imageNamed:@"sound_playtimes@3x.png"];
            cell.imageV3.image=[UIImage imageNamed:@"album_tracks@3x.png"];
            
            NSString *str= [[self.arr objectAtIndex:indexPath.section] objectForKey:@"title"];
            cell.lableBT.text=str;
            cell.imageGD.image=[UIImage imageNamed:@"findsection_logo@2x.png"];
            cell.lableGD.text=@"更多 >";
            cell.imV.image=[UIImage imageNamed:@"cell_arrow_all.png"];
            [cell.button addTarget:self action:@selector(button:) forControlEvents:UIControlEventTouchUpInside];
            cell.button.tag=indexPath.section;
            return cell;

        }else{
            SortDetailedTVC *cell=[tableView dequeueReusableCellWithIdentifier:@"aaa"];
            if (!cell) {
                cell=[[SortDetailedTVC alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"aaa"];
                
            }
            cell.lable1.text=[[[[self.arr objectAtIndex:indexPath.section] objectForKey:@"list"] objectAtIndex:indexPath.row] objectForKey:@"title"];
            cell.lable2.text=[[[[self.arr objectAtIndex:indexPath.section] objectForKey:@"list"] objectAtIndex:indexPath.row] objectForKey:@"intro"];
            CGFloat f=[[[[[self.arr objectAtIndex:indexPath.section] objectForKey:@"list"] objectAtIndex:indexPath.row] objectForKey:@"playsCounts"] floatValue];
            if (f<10000) {
                cell.lable3.text=[NSString stringWithFormat:@"%.0f",f];
            }else{
                cell.lable3.text=[NSString stringWithFormat:@"%.2f万",f/10000];
            }

//            cell.lable3.text=[[[[[self.arr objectAtIndex:indexPath.section] objectForKey:@"list"] objectAtIndex:indexPath.row] objectForKey:@"playsCounts"] stringValue];
            NSString  *str=[[[[[self.arr objectAtIndex:indexPath.section] objectForKey:@"list"] objectAtIndex:indexPath.row] objectForKey:@"tracksCounts"] stringValue];
            cell.lable4.text=[str stringByAppendingString:@"集"];
            
            [cell.imageV1 sd_setImageWithURL:[NSURL URLWithString:[[[[self.arr objectAtIndex:indexPath.section] objectForKey:@"list"] objectAtIndex:indexPath.row] objectForKey:@"coverMiddle"]] placeholderImage:[UIImage imageNamed:@"find_kind_btn_default@3x.png"]];
            cell.imageV2.image=[UIImage imageNamed:@"sound_playtimes@3x"];
            cell.imageV3.image=[UIImage imageNamed:@"album_tracks@3x.png"];
            
            cell.imV.image=[UIImage imageNamed:@"cell_arrow_all.png"];
            
            
            return cell;
 
        }
        
    }
    
            return NULL;
   }

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if ([[self.arr objectAtIndex:0] objectForKey:@"contentType"]==nil){
      if (indexPath.section==0) {
        return FM_Screen_Pts_Height*60;
      }else if (indexPath.row==0){
        return FM_Screen_Pts_Width*70+FM_Screen_Pts_Height*40+FM_Screen_Pts_Height*50;
      }else{
          return FM_Screen_Pts_Width*70+FM_Screen_Pts_Height*40;
      }
        
    }else{
        if (indexPath.row==0){
            return FM_Screen_Pts_Width*70+FM_Screen_Pts_Height*40+FM_Screen_Pts_Height*50;
        }else{
            return FM_Screen_Pts_Width*70+FM_Screen_Pts_Height*40;
        }
    }
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return FM_Screen_Pts_Height*15;
}
///button 点击
-(void)button:(UIButton *)bu
{
    
       self.block1([[self.arr objectAtIndex:bu.tag] objectForKey:@"title"],[[self.arr objectAtIndex:bu.tag] objectForKey:@"tagName"]);
    
}


-(void)applyLayoutAttributes:(UICollectionViewLayoutAttributes *)layoutAttributes
{
    self.tableView.frame=self.contentView.bounds;
    
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if ([[self.arr objectAtIndex:0] objectForKey:@"contentType"]==nil) {
    if (indexPath.section==0 && indexPath.row==0) {
       
        
        self.block();
    }else{
        
        if ([[self.arr objectAtIndex:2] objectForKey:@"tagName"]==nil) {
            if (indexPath.section==2) {
          ///////小老鼠屎
                self.blockLaoShuShi([[[self.arr objectAtIndex:2] objectForKey:@"list"] objectAtIndex:indexPath.row]);
                
                
                NSLog(@"*******%@",[[[self.arr objectAtIndex:2] objectForKey:@"list"] objectAtIndex:indexPath.row]);
                
                
                
                
                
            }else{
                 self.blockzheng([[[self.arr objectAtIndex:indexPath.section] objectForKey:@"list"] objectAtIndex:indexPath.row]);
            }

        }else{
            
            self.blockzheng([[[self.arr objectAtIndex:indexPath.section] objectForKey:@"list"] objectAtIndex:indexPath.row]);
        
              }
        
           }
        }else{
      
        self.blockzheng([[[self.arr objectAtIndex:indexPath.section] objectForKey:@"list"] objectAtIndex:indexPath.row]);
    
        
        }
   
}

-(void)buttonqwe:(UIButton *)bu
{
    NSLog(@"1111");
    
    
    self.blocklao([[self.arr objectAtIndex:2] objectForKey:@"title"]);
    
    
}



@end
